//
//  FeedBackViewController.m
//  fitnessmanage
//
//  Created by wujian on 2017/12/18.
//  Copyright © 2017年 zongquankeji. All rights reserved.
//

#import "FeedBackViewController.h"
#import "FeedBackTableViewCell.h"
#import "FeedBackDetailViewController.h"

@interface FeedBackViewController ()<UITableViewDataSource,UITableViewDelegate>

@property(nonatomic,weak)UITableView *tableView;

@property(nonatomic,strong)NSMutableArray *dataSource;

@end

@implementation FeedBackViewController

- (void)viewDidLoad {
    
    [super viewDidLoad];

    self.title = @"意见反馈";
    
    self.view.backgroundColor = BackGroundColor;
    
    [self createSubView];
}

-(void)createSubView{
    
    UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.frame style:UITableViewStylePlain];
    tableView.dataSource = self;
    tableView.delegate = self;
    tableView.showsVerticalScrollIndicator = NO;
    [tableView registerClass:[FeedBackTableViewCell class] forCellReuseIdentifier:@"FeedBackTableViewCell"];
    tableView.separatorStyle = UITableViewCellSelectionStyleNone;
    tableView.backgroundColor = BackGroundColor;
    [self.view addSubview:tableView];
    [tableView mas_remakeConstraints:^(MASConstraintMaker *make) {
        
        make.edges.mas_equalTo(self.view);
    }];
    self.tableView = tableView;
    
    UIView *tableHeadView = [[UIView alloc] init];
    tableHeadView.backgroundColor = CSColorFromRGB(0xfaf6eb);
    [self.view addSubview:tableHeadView];
    
    UILabel *titleLabel = [[UILabel alloc] init];
    titleLabel.text = @"请您选择想要反馈的类别";
    titleLabel.font = MidFont;
    titleLabel.textColor = CSColorFromRGB(0x737373);
    [tableHeadView addSubview:titleLabel];
    [titleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(tableHeadView);
        make.left.mas_equalTo(self.view).offset(15);
    }];
    [tableHeadView mas_remakeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(tableView);
        make.left.width.mas_equalTo(self.view);
        make.height.mas_equalTo(40);
    }];
    
    [tableHeadView setNeedsLayout];
    [tableHeadView layoutIfNeeded];
    
    tableView.tableHeaderView = tableHeadView;
}

#pragma mark UITableViewDataSource

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.dataSource.count;
}

#pragma mark UITableViewDelegate

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    
    return 0.00001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 0.00001;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    return 60;
}


-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    FeedBackTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"FeedBackTableViewCell"];
    
    cell.nameLabel.text = [self.dataSource objectAtIndex:indexPath.row];
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}


-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    
    FeedBackDetailViewController *feedBackDetailVC = [[FeedBackDetailViewController alloc] init];
    
    feedBackDetailVC.title = [self.dataSource objectAtIndex:indexPath.row];
    
    [self.navigationController pushViewController:feedBackDetailVC animated:YES];
}


#pragma mark Get
-(NSMutableArray *)dataSource{
    
    if (!_dataSource) {
        
        _dataSource = [[NSMutableArray alloc] init];
     
        [_dataSource addObject:@"产品BUG提交"];
        
        [_dataSource addObject:@"赞扬产品相关功能"];
        
        [_dataSource addObject:@"产品优化建议"];
        
        [_dataSource addObject:@"产品吐槽"];
    }
    
    return _dataSource;
}

@end
